package cn.itcast.task;

import cn.itcast.domain.User;
import cn.itcast.service.user.UserService;


import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//类
public class MyTask {
    @Autowired
    private  UserService userService;
    @Autowired
    private AmqpTemplate amqpTemplate;

    //方法
    public void aaa() {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("MM-dd");
        String birthday = format.format(date);
        System.out.println("111111111111"+birthday);
        List<User> list = userService.findBybirthday(birthday);
        System.out.println("111111111"+list);
        // 给过生日的用户的邮箱发一封祝福邮件；
        //任务：充当生产者望消息中间件中放入内容
        if (list!=null){
            for (User user: list){
                Map map = new HashMap();
                map.put("email",user.getEmail());
                map.put("emailMsg","尊敬的用户，今天是您的生日，祝您生日快乐哦！工作再忙也别忘记吃蛋糕噢~");
                amqpTemplate.convertAndSend("saas.birthday.email",map);
            }
        }
    }
}
